<?php
namespace app\api\model;
use think\Model;
class Shopcart extends Model
{
    public function index()
    {   
       
    }


     public function getGoods($token,$vid)
      {
      	  $data = [
              'token'=>$token,
              'goods_id'=>$vid 
      	  ];
          
      	 return  $goods=model('ShopCart')
      	         ->where($data)
      	         ->find();
      }


      public function getGoodsCart($token)
      {
           $data = [
              'zhuangtai' =>1,
              'token'=>$token
           ];
          return $goods=model('Shopcart')
                            ->field('num,goods_id,name,price,checked,pzleixing')
                            ->where($data)
                            ->select();

      }

       // public function removeOutCart($token,$goodsId)
       // { 
       //    $data = [
       //       'zhuangtai' =>1,
       //       'token'=>$token,
       //        'goods_id'=>$goodsId
       //     ];
       //     return $count=model('shopcart')->where($data)->setDec('num');
       // }
      

      public function selectedAll($token)
      {    
          $data = [
               'token'=>$token,
              'zhuangtai'=>1,
               'checked'=>0
          ];
           $result = model('shopcart')->where($data)->select();
             $count = 0;
             for($i=0;$i<count($result);$i++){
                  model('shopcart')->where('id',$result[$i]->id)->setField('checked',1);
                  $count++;
             }     
             return $count;  
      }


      public function selectedNo($token)
      {
          $data = [
               'token'=>$token,
              'zhuangtai'=>1,
               'checked'=>1
          ];
           $result = model('shopcart')->where($data)->select();
             $count = 0;
             for($i=0;$i<count($result);$i++){
                  model('shopcart')->where('id',$result[$i]->id)->setField('checked',0);
                  $count++;
             }     
             return $count;  

      }
      //获取购物车已选中的全部商品
      public function selectedGoods()
      {
        $data = [
           'checked'=>1,
           'zhuangtai'=>1,
        ];
        $result = model('shopcart')->where($data)->select();
        return $result;
      }
}